<?php
class Model_GoalList
{
    protected $_table;

    public function getTable()
    {
        if (null === $this->_table) {
            require_once APPLICATION_PATH . '/models/DbTable/Goal.php';
            $this->_table = new Model_DbTable_Goal;
        }
        return $this->_table;
    }

    public function fetchEntries()
    {
        return $this->getTable()->fetchAll('1')->toArray();
    }

	public function fetchEntriesByUser($user)
    {
		$table 		= $this->getTable();
        $selectOb 	= $table->select()->where('user_id = ?', $user->id);
		return $this->getTable()->fetchAll($selectOb)->toArray();
    }

	public function add($goal)
    {
		$table 		= $this->getTable();
		$goalData = array(
             'title' 			=> $goal->title,
             'user_id'			=> $goal->user_id,
			 'deadline_date'	=> $goal->deadline_date->toString('YYYY-MM-dd HH:mm:ss')
        );
		
		$table->insert($goalData);
		$selectOb 	= $table->select()->where('user_id = ?', $goal->user_id);
		return $this->getTable()->fetchAll($selectOb)->toArray();
    }
	
}